package site.shenjie.my.loadbalanced.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import site.shenjie.my.loadbalanced.annotation.MyLoadBalanced;

@RestController
public class MyLoadBalancedController {

    @RequestMapping("/index")
    public String index() {
        return "<h1>hello, welcome to my load balanced controller</h1>";
    }

    @MyLoadBalanced
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("/call/hello")
    public void callHello() {
        for (int i = 0; i < 100; i++) {
            System.out.println(restTemplate.getForObject("http://eureka-client-user-service/user/hello", String.class));
        }
    }
}
